let ipt: null | HTMLInputElement = null;

export default function fetchLocalFile(accept: string): Promise<File[]> {
    if (!ipt) {
        ipt = document.createElement('input');
        ipt.type = 'file';
        ipt.style.position = 'fixed';
        ipt.style.left = '100000px';
        ipt.style.opacity = '0';
    }

    return new Promise((resolve) => {
        // @ts-ignore
        ipt.accept =
            // @ts-ignore
            ipt.onchange = () => {
                // @ts-ignore
                resolve(ipt?.files ? [].slice.call(ipt?.files) : []);
                // @ts-ignore
                ipt.value = '';
            };
        ipt!.click();
    });
}
